/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2023-11-17
 * Time: 23:15
 */
public class Solution {

    /**
     *  方法一: 遍历, 并使用数组检测是否重复
     */
    public int findCenter1(int[][] edges) {
        int len = edges.length;
        int[] arr = new int[len+2];
        for (int i = 0; i < len; i++) {
            int from = edges[i][0];
            int to = edges[i][1];
            if (arr[from] == 1) {
                return from;
            }
            if (arr[to] == 1) {
                return to;
            }
            arr[from] = 1;
            arr[to] = 1;
        }
        return -1;
    }

    /**
     *  方法二: 因为任意两条边都有公共节点, 所以只需要判断两条边的公共节点就可以了
     */
    public int findCenter2(int[][] edges) {
        return edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1] ? edges[0][0] : edges[0][1];
    }
}
